Skip to content

fix: use virtual module for runtime auto-import - #3

Merged
Peyton-Spencer merged 1 commit into
mainfrom
fix/runtime-auto-import
Feb 9, 2026
Merged

fix: use virtual module for runtime auto-import#3
Peyton-Spencer merged 1 commit into
mainfrom
fix/runtime-auto-import

Conversation

@Peyton-Spencer

Copy link
Copy Markdown
Contributor

Summary

  • Browsers cannot resolve bare module specifiers (import "solid-grab") in inline <script type="module"> tags — Vite only processes scripts from the original HTML, not those injected by transformIndexHtml
  • Added virtual module (virtual:solid-grab-init) with resolveId/load hooks
  • Added configureServer middleware that rewrites /@solid-grab/init/@id/virtual:solid-grab-init so Vite's dev server resolves the bare import
  • HTML now injects <script type="module" src="/@solid-grab/init"> instead of inline code

Test plan

  • All 55 tests pass
  • Build succeeds with clean DTS
  • Tested in ditto-app: runtime loads, overlay activates on Alt+hover, source locations copy to clipboard

🤖 Generated with Claude Code

The previous approach injected an inline `<script type="module">` with
`import "solid-grab"` via transformIndexHtml. Browsers cannot resolve
bare module specifiers in inline scripts — Vite only processes scripts
that were in the original HTML, not those injected by plugins.

Fix: use a virtual module (`virtual:solid-grab-init`) served through
Vite's dev server via configureServer middleware. The HTML now gets a
`<script type="module" src="/@solid-grab/init">` tag, which the browser
fetches as a normal module request. Vite's middleware rewrites the URL
to `/@id/virtual:solid-grab-init`, which resolves through the plugin's
resolveId/load hooks and gets the bare import properly resolved.

Tested and working in ditto-app — overlay activates on Alt+hover.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Peyton-Spencer
Peyton-Spencer merged commit ec7c6af into main Feb 9, 2026
1 check passed
@Peyton-Spencer
Peyton-Spencer deleted the fix/runtime-auto-import branch February 9, 2026 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant